package com.example.kotlinlearningproject.audioplayer

import android.content.res.AssetManager
import android.media.AudioAttributes
import android.media.SoundPool

class SoundPoolPlayer {
    private lateinit var mSoundPool: SoundPool
    private var audioAttributes: AudioAttributes? = null
    private var soundIdIKnow = 0

    public fun preload(assets: AssetManager) {
        audioAttributes = AudioAttributes.Builder()
            .setContentType(AudioAttributes.CONTENT_TYPE_MUSIC)
            .setUsage(AudioAttributes.USAGE_MEDIA)
            .build()

        mSoundPool = SoundPool.Builder()
            .setMaxStreams(3)
            .setAudioAttributes(audioAttributes)
            .build()

        soundIdIKnow = mSoundPool.load(assets.openFd("iknow.mp3"), 1)

    }

    public fun playIKnowMp3() {
        println("play")
        mSoundPool.play(soundIdIKnow, 1F, 1F, 0, 0, 1F);
    }
}

